package com.example.administrator.pomelostreet.tata;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.pomelostreet.R;
import com.example.administrator.pomelostreet.tatajavabean.recommend_forums;

import java.util.List;

/**
 * 作者：韩飞  日期：2017/2/8.
 */

public class RecycleViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private LayoutInflater mLayoutInflater;
    private Context context;
    private List<recommend_forums> list;




    //建立枚举2个item类型
    public enum ITEM_TYPE{
        ITEM1,
        ITEM2
    }


    public RecycleViewAdapter(Context context, List<recommend_forums> list  ){
        this.list=list;
        this.context=context;
        this.mLayoutInflater = LayoutInflater.from(context);


    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(context).inflate(R.layout.tata_recycle_layout,parent,false);
        return new Item1ViewHolder(itemView);



    }
        //加载Item view的时候根据不同TYPE加载不同的布局


//        if(viewType == ITEM_TYPE.ITEM1.ordinal()){
//            return new Item1ViewHolder(mLayoutInflater.inflate(R.layout.tata_recycle_layout,parent,false));
//
//        }else{
//
//            return new Item2ViewHolder(mLayoutInflater.inflate(R.layout.tata_recycle_layout_2,parent,false));
//        }




    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if(holder  instanceof  Item1ViewHolder){

            ((Item1ViewHolder) holder).mtextview1.setText(list.get(position).getName());
            Glide.with(context).load(list.get(position).getIcon()).into(((Item1ViewHolder) holder).mimageView1);
            Glide.with(context).load(list.get(position).getIcon2()).into(((Item1ViewHolder) holder).mimageView2);
            Glide.with(context).load(list.get(position).getIcon3()).into(((Item1ViewHolder) holder).mimageView3);

        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

//设置ITEM类型
//    @Override
//    public int getItemViewType(int position) {
//        return position % 3 == 0 ? ITEM_TYPE.ITEM1.ordinal() : ITEM_TYPE.ITEM2.ordinal();
//    }
//
//    @Override
//    public int getItemCount() {
//        return list == null ? 0 : list.size();
//    }

    //item1的viewholder
    public  class Item1ViewHolder extends RecyclerView.ViewHolder{
        TextView mtextview1;
        ImageView mimageView1;
        ImageView mimageView2;
        ImageView mimageView3;
        public Item1ViewHolder(View itemView) {
            super(itemView);
            mtextview1= (TextView) itemView.findViewById(R.id.tv_title);
            mimageView1= (ImageView) itemView.findViewById(R.id.iv_titile1);
            mimageView2= (ImageView) itemView.findViewById(R.id.iv_titile2);
            mimageView3= (ImageView) itemView.findViewById(R.id.iv_titile3);

        }
    }
    //item2的viewholder
//    public static  class  Item2ViewHolder extends RecyclerView.ViewHolder{
//        TextView mtextview2;
//        ImageView imageView4;
//        public Item2ViewHolder(View itemView) {
//            super(itemView);
//            mtextview2= (TextView) itemView.findViewById(R.id.tv_title2);
//            imageView4= (ImageView) itemView.findViewById(R.id.iv_titile4);
//        }
//    }


}
